package bobaini.com.topic_exchange;

import bobaini.com.util.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * ClassName: Consumer02
 * author: bob.ly
 * Version: 1.0.0
 * DateTime: 2021/07/27-15:39:00
 * Description:
 */
public class Consumer02 {
    private static final String TOPIC_EXCHANGE = "topic.exchange";
    private static final String QUEUE_02 = "Q2";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(TOPIC_EXCHANGE, BuiltinExchangeType.TOPIC);
        channel.queueDeclare(QUEUE_02, true, false, false, null);
        channel.queueBind(QUEUE_02, TOPIC_EXCHANGE, "*.*.rabbit");
        channel.queueBind(QUEUE_02, TOPIC_EXCHANGE, "lazy.#");
        DeliverCallback deliverCallback = (tag, message) -> {
            String s = new String(message.getBody(), "UTF-8");
            System.out.println("当前队列Q2接受的消息:" + s);
        };
        channel.basicConsume(QUEUE_02, true, deliverCallback, s -> {
            System.out.println("取消时候回调的接口");
        });
    }
}
